package com.example.linxilite.screen

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import coil.compose.AsyncImage
import com.example.linxilite.model.User

private val sampleUsers = listOf(
    User(1, "Alice", "女", "https://randomuser.me/api/portraits/women/1.jpg"),
    User(2, "Bob", "男", "https://randomuser.me/api/portraits/men/2.jpg"),
    User(3, "Cindy", "女", "https://randomuser.me/api/portraits/women/3.jpg"),
    User(4, "David", "男", "https://randomuser.me/api/portraits/men/4.jpg"),
    User(5, "Emma", "女", "https://randomuser.me/api/portraits/women/5.jpg")
)


@Composable
fun MatchScreen(navController: NavController){
    var currentIndex by remember { mutableStateOf(0) }
    val user = sampleUsers[currentIndex]

    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(24.dp),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center
    ) {
        // 用户头像
        AsyncImage(
            model = user.avatarUrl,
            contentDescription = null,
            modifier = Modifier
                .size(200.dp)
                .clip(CircleShape)
        )

        Spacer(Modifier.height(16.dp))
        Text("${user.name}（${user.gender}）", fontSize = 22.sp, fontWeight = FontWeight.Bold)

        Spacer(Modifier.height(32.dp))

        Row {
            Button(
                onClick = {
                    currentIndex = (currentIndex + 1) % sampleUsers.size
                }
            ) { Text("换一个") }

            Spacer(Modifier.width(24.dp))

            Button(
                onClick = {
                    navController.navigate("chat/${user.name}")
                }
            ) { Text("开始聊天") }
        }
    }
}